package com.wissen.temperatureapp.client.widgets;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
//import com.google.gwt.user.client.ui.HasHorizontalAlignment;
//import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.widgetideas.client.ProgressBar;
import com.wissen.temperatureapp.client.controller.TempController;
import com.wissen.temperatureapp.client.observers.TemperatureObserver;

/**
 * Class represents a Progress Bar widget. Provides Progress UI for user.
 * 
 * @author Mayur Birari
 * 
 */
public class ProgressBarWidget extends Composite implements TemperatureObserver {

    private HorizontalPanel progressbarPanel;

    private ProgressBar progressbar;
    
    private FlexTable      progressbarTable;

    public ProgressBarWidget(){}
    public ProgressBarWidget(Double value) {
        init();

       progressbarPanel.add(progressbarTable);
        initWidget(progressbarPanel);
        progressbar.setProgress(value);
        TempController.getInstance().addTempObserver(this);
    }

    private void init() {
    	progressbarPanel = new HorizontalPanel();        
    	progressbar=new ProgressBar(0.0,100.0,0.0); 
    	progressbar.setWidth("200%");
        //creating table
    	progressbarTable = new FlexTable();
    	progressbarTable.setText(0, 0, "Progress Bar : ");
    	progressbarTable.setWidget(1, 0,progressbar);
    	//progressbarTable.getFlexCellFormatter().setColSpan(2, 0, 2);
    	//progressbarTable.getFlexCellFormatter().setAlignment(3, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
    }
    
    public void notifyConvertFailed(String errorMessage) {
        Window.alert("Conversion fail: " + errorMessage);
    }
    
    public void notifyConvertSucceeded(Double fvalue) {
    	progressbar.setProgress(fvalue);
    }
}
